#!/bin/bash
preip_filepath=`dirname $0`'/check_ip.cf'
if [ ! -e $preip_filepath ];then
        touch $preip_filepath
fi
preip=`cat $preip_filepath`
curip=`curl -s http://20140507.ip138.com/ic.asp| awk -F"[][]" '{print $2}'`
curip=`echo $curip | sed 's/^ *\| *$//g'`

echo 'preip:'$preip
echo 'curip:'$curip

if [ "$curip" = "$preip" ];then
        echo "same ip"
else
        echo "different ip,mail notification."
        subject=`date +"%Y-%m-%d %H:%M"`
        subject="[ "$subject" ] "$curip
        #echo $subject
        echo $curip | mail -s """$subject""" coolinc@163.com
        echo $curip > $preip_filepath
fi